//螺旋遍历二维数组  力扣LCR146
class Solution {
public:
	vector<int> spiralArray(vector<vector<int>>& array) {
		if (array.size() == 0 || array[0].size() == 0) {
			return {};
		}
		int index = array.size();
		int column = array[0].size();
		vector<int> ans(index*column);
		int top = 0, bottom = index-1, left = 0, right = column-1;
		int i,j;
		int cnt = 0;
		while(top <= bottom && left <= right)
		{
			for(j = left; j <= right; j++)
				ans[cnt++] = array[top][j];
			
			for(i = top+1; i <= bottom; i++)
				ans[cnt++] = array[i][right];
			
			if(top < bottom && left < right)
			{
				for(j = right - 1; j > left; j--)
					ans[cnt++] = array[bottom][j];
				
				for(i = bottom; i > top; i--)
					ans[cnt++] = array[i][left];
			}
			top++;
			bottom--;
			left++;
			right--;
		}
		return ans;
	}
};
